<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		$('#zzgl_xygl_datagrid').datagrid({
			url : '${pageContext.request.contextPath}/school/collegeAction!datagrid.action',
			fit : true,
			fitColumns : true,
			border : false,
			rownumbers : true,
			pagination : true,
			sortName : 'classId',
			idField : 'id',
			singleSelect : true,
			//checkOnSelect:false,
			columns : [ [ {
				field : 'id',
				title : '编号',
				width : 100,
				align : 'center',
				checkbox : true
			}, {
				field : 'collegeId',
				title : '学院编号',
				width : 150,
				align : 'center',
				sortable : true
			//hidden:true
			}, {
				field : 'collegeName',
				title : '学院',
				width : 150,
				align : 'center',
				sortable : true
			}, {
				field : 'schoolName',
				title : '学校',
				width : 150,
				align : 'center',
				sortable : true
			}, {
				field : 'isEnble',
				title : '启用',
				width : 150,
				align : 'center',
				sortable : true
			} ] ],
			toolbar : [ {
				text : '查看所有',
				iconCls : 'icon-reload',
				handler : function() {
					searchAllFun();
				}
			}, '-', {
				text : '编辑',
				iconCls : 'icon-edit',
				handler : function() {
					modify();
				}
			}, '-', {
				text : '添加',
				iconCls : 'icon-add',
				handler : function() {
					append();
				}

			}, '-', {
				text : '删除',
				iconCls : 'icon-remove',
				handler : function() {
					remove();
				}
			} ]
		});
		$('#zzgl_xygl_collegeIdCmb').combobox({
			url : '${pageContext.request.contextPath}/school/collegeAction!getCollegeCmb.action',
			valueField : 'collegeId',
			textField : 'collegeId'
		});
		$('#zzgl_xygl_collegeCmb').combobox({
			url : '${pageContext.request.contextPath}/school/collegeAction!getCollegeCmb.action',
			valueField : 'collegeName',
			textField : 'collegeName'
		});
	});
	function searchFun() {
		$('#zzgl_xygl_datagrid').datagrid('load', {
			collegeId : $('#zzgl_xygl_collegeIdCmb').combobox('getText'),
			collegeName : $('#zzgl_xygl_collegeCmb').combobox('getText'),
			isEnble : $('#zzgl_xygl_isEnbleCmb').combobox('getText')
		});
	}
	function searchAllFun() {
		var collegeId = $('#zzgl_xygl_collegeIdCmb').combobox('setText', '');
		var collegeName = $('#zzgl_xygl_collegeCmb').combobox('setText', '');
		var isEnble = $('#zzgl_xygl_majorCmb').combobox('setText', '---');
		$('#zzgl_xygl_datagrid').datagrid('load', {});
	}
	function append(){
		$('#zzgl_xygl_addform input[name=collegeId]').val('');
		$('#zzgl_xygl_addform input[name=collegeName]').val('');
		$('#zzgl_xygl_addform input[name=schoolName]').val('科技学院');
		$('#zzgl_xygl_addDialog').dialog('open');
	}
	function remove(){
		var rows=$('#zzgl_xygl_datagrid').datagrid('getChecked');
		var collegeIds=[];
		if(rows.length>0){
			$.messager.confirm('确认','是否确认删除选中的记录？',function(r){
			if(r){
				for(var i=0;i<rows.length;i++){
					collegeIds.push(rows[i].collegeId);
				}
				$.ajax({
					url:'${pageContext.request.contextPath}/school/collegeAction!remove.action',
					data:{collegeIds:collegeIds.join(',')},
					dataType:'json',
					success:function(r){
						$('#zzgl_xygl_datagrid').datagrid('load');
						$('#zzgl_xygl_datagrid').datagrid('unselectAll');
						$.messager.show({
							title:'提示',
							msg:r.msg
						});
					}
				});
			}
		});
		}else{
			$.messager.alert('提示','请选择你要操作的行!');
		}
	}
	function modify(){
		$('#zzgl_xygl_editform input').val('');
		var rows =$('#zzgl_xygl_datagrid').datagrid('getChecked');
		if(rows.length==1){
			var d=$('<div style="background:#f5f5f5;"/>').dialog({
				width:530, 
				height:250,
				href:'${pageContext.request.contextPath}/zzgl/xyglEditDialog.jsp',
				modal:true,
				title:'编辑',
				buttons:[{
					text:'确定',
					iconCls:'icon-ok',
					handler:function(){
						$('#zzgl_xygl_editform').form('submit',{
							url:'${pageContext.request.contextPath}/school/collegeAction!edit.action',
							success:function(r){
								var obj=jQuery.parseJSON(r);
								if(obj.success){
									$('#zzgl_xygl_datagrid').datagrid('load');
									d.dialog('close');
								}
								$.messager.show({
									title:'提示',
									msg:obj.msg
								});
							}
						});
					}
				}],
				onClose:function(){
					$(this).dialog('destroy');
				},
				onLoad:function(){
					$('#zzgl_xygl_editform').form('load',rows[0]);
				}
			});
		}else{
			$.messager.alert('提示','请选择你要操作一行!');
		}
	}
</script>
</head>
<body>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'north',iconCls:'icon-table_edit',split:true" style="fit:true;overflow:hidden;background-color:#F5F5F5;">
		<table>
			<tr>
				<td style="padding:5px 5px 15px 15px;">学院编号 ：<input id="zzgl_xygl_collegeIdCmb" name="collegeId" style="width:100px;" />
				</td>
				<td style="padding:5px 5px 15px 15px;">学院名称：<input id="zzgl_xygl_collegeCmb" name="collegeName" style="width:100px;" />
				</td>
				<td style="padding:5px 5px 15px 15px;">启用： <select id="zzgl_xygl_isEnbleCmb" class="easyui-combobox" name="isEnble" style="width:50px;">
						<option ></option>
						<option value="1">是</option>
						<option value="0">否</option>
				</select></td>
				<td style="padding:5px 5px 15px 25px;"><a href="#" class="easyui-linkbutton" data-options="border:false,iconCls:'icon-search',plain:true" onclick="searchFun()">查询</a>
				</td>
			</tr>
		</table>
	</div>
	<div data-options="region:'center',iconCls:'icon-table_multiple',title:'学院信息',border:false" style="height:200px;">
		<table id="zzgl_xygl_datagrid"></table>
	</div>
</div>
<div id="zzgl_xygl_addDialog" class="easyui-dialog" style="width:530px;height:250px;padding:15px 15px 15px 15px;text-align:right;background:#f5f5f5;" data-options="closed:true,modal:true,title:'添加',buttons:[{
			text:'确定',
			iconCls:'icon-ok',
			handler:function(){
				$('#zzgl_xygl_addform').form('submit',{
				url:'${pageContext.request.contextPath}/school/collegeAction!add.action',
				success:function(data){
					var obj=jQuery.parseJSON(data);
					if(obj.success){
						$('#zzgl_xygl_datagrid').datagrid('load');
						$('#zzgl_xygl_addDialog').dialog('close');
					}
					$.messager.show({
						title:'提示',
						msg:obj.msg
					});
				}});
			}
		}]">
	<form id="zzgl_xygl_addform" method="post">
		<table>
			<tr>
				<td style="padding:10px 5px 3px 15px;">学院编号 ：<input name="collegeId" style="width:100px;" class="easyui-validatebox"  data-options="required:true,validType:'length[0,10]',missingMessage:'必填！'" />
				</td>
				<td style="padding:10px 5px 3px 15px;">学院名称 ：<input name="collegeName" style="width:100px;" class="easyui-validatebox"  data-options="required:true,validType:'length[0,10]',missingMessage:'必填！'" />
				</td>
			</tr>
			<tr>
				<td style="padding:3px 5px 3px 15px;">所属学校 ：<input name="schoolName" value="科技学院" style="width:100px;background:#f5f5f5;" readonly="readonly" />
				</td>
				<td style="padding:3px 5px 3px 15px;">是否启用 ：<input name="isEnble" checked="true" value="是" type="radio">是<input name="isEnble" value="否" type="radio">否</td>
			</tr>
		</table>
	</form>
</div>
</body>
</html>


